<?php

declare(strict_types=1);

namespace app\common\controller;

use app\common\service\DingTalk as DingTalkService;
use think\Request;
use app\common\controller\Base;
use app\common\validate\DingTalk as DingTalkValidate;

class DingTalk extends Base
{
    protected $request;
    protected $service;
    protected $validate;
    public function __construct(Request $request, DingTalkService $service, DingTalkValidate $validate)
    {
        $this->request = $request;
        $this->service = $service;
        $this->validate = $validate;
    }

    /**
     * @describe 发送文本消息类型工作通知
     * @author: Bobo
     * @date: 2025-01-10 11:35:22 
     * @param [type] @required
     * @return Renderable
     */
    public function SendActionCardJobNotificationMessage()
    {
        $param = $this->request->param();
        if (!$this->validate->scene('SendActionCardJobNotificationMessage')->check($param)) {
            return $this->returnJsonData(1, [], $this->validate->getError());
        }
        $title = $this->request->param('title') ?? '';
        $content = $this->request->param('content') ?? '';
        $url = $this->request->param('url') ?? '';
        $coverImage = $this->request->param('coverImage') ?? '';
        $userList = $this->request->param('userList') ?? '';
        $result = $this->service->SendActionCardJobNotificationMessage($title, $content, $url, $userList, [], $coverImage);


        $code = $result['code'];
        $data = $result['data'] ?? [];
        $message = $result['message'] ?? "";
        return $this->returnJsonData($code, $data, $message);
    }

    /**
     * @describe 发送卡片消息类型工作通知
     * @author: Bobo
     * @date: 2025-01-13 15:35:22 
     * @param [type] @required
     * @return Renderable
     */
    public function SendTextJobNotificationMessage()
    {
        $content = $this->request->param('content');
        $userList = $this->request->param('userList');
        $result = $this->service->SendTextJobNotificationMessage($content, $userList);
        $code = $result['code'];
        $data = $result['data'] ?? [];
        $message = $result['message'] ?? "";
        return $this->returnJsonData($code, $data, $message);
    }

    /**
     * @describe 发送文本消息类型群消息
     * @author: Bobo
     * @date: 2025-01-15 11:57:27 
     * @param [type] @required
     * @return Renderable
     */
    public function SendTextGroupChatMessage()
    {
        $content = $this->request->param('content');
        $dingtalkGroupId = $this->request->param('dingtalkGroupId');

        $result = $this->service->SendTextGroupChatMessage($content, $dingtalkGroupId);

        $code = $result['code'];
        $data = $result['data'] ?? [];
        $message = $result['message'] ?? "";

        return $this->returnJsonData($code, $data, $message);
    }

    /**
     * @describe 发送卡片消息类型群消息
     * @author: Bobo
     * @date: 2025-01-15 14:44:20 
     * @param [type] @required
     * @return Renderable
     */
    public function SendActionCardGroupChatMessage()
    {
        $title = $this->request->param('title') ?? '';
        $content = $this->request->param('content') ?? '';
        $url = $this->request->param('url') ?? '';
        $dingtalkGroupId = $this->request->param('dingtalkGroupId') ?? 0;
        $coverImage = $this->request->param('coverImage') ?? '';
        $result = $this->service->SendActionCardGroupChatMessage($title, $content, $url, $dingtalkGroupId, $coverImage);
        $code = $result['code'];
        $data = $res['data'] ?? [];
        $message = $res['message'] ?? "";
        return $this->returnJsonData($code, $data, $message);
    }


    /**
     * @describe
     * @author: Bobo
     * @date: 2025-02-27 17:32:10 
     * @param [type] @required
     * @return Renderable
     */
    public function getAllOperatorUserId()
    {
        $result = $this->service->getAllOperatorUserId();
        $code = $result['code'];
        $data = $res['data'] ?? [];
        $message = $res['message'] ?? "";
        return $this->returnJsonData($code, $data, $message);
    }
}
